package org.oos.dao.impl;

import static org.oos.ApiUrlProvider.SiteReviews;

import org.oos.atom.ReviewFeed;
import org.oos.atom.entries.ReviewEntry;
import org.oos.atom.entries.impl.ReviewEntryImpl;
import org.oos.atom.impl.ReviewFeedImpl;
import org.oos.dao.ReviewDao;
import org.oos.dao.lists.impl.FullAccessDynamicList;

import com.google.api.client.http.GenericUrl;

/**
 * Internal implementation of the {@link ReviewDao}. This class should not be
 * used outside of this package.
 * 
 * @author pablo.gonzalez@11870.com
 * 
 */
public class ReviewDaoImpl extends
		ReadOnlyAbstractDao<ReviewEntry, ReviewFeed<ReviewEntry>> implements
		ReviewDao {

	public ReviewDaoImpl() {
		super(ReviewFeedImpl.class, ReviewEntryImpl.class);
	}

	/**
	 * This variable is used to complete the url for the review
	 */
	public String siteSlug;

	@Override
	public GenericUrl getFeedUrl() {
		if (siteSlug != null) {
			return SiteReviews.getUrl(siteSlug);
		} else {
			throw new IllegalStateException("There must be a slug");
		}
	}

	@Override
	public void setSiteSlug(String siteSlug) {
		this.siteSlug = siteSlug;
	}

	@SuppressWarnings("unchecked")
	@Override
	protected FullAccessDynamicList<ReviewEntry, ReviewFeed<ReviewEntry>> getList(ReviewFeed feed) {
		return new FullAccessDynamicList<ReviewEntry, ReviewFeed<ReviewEntry>>(this, feed);
	}

}
